
<div class="toolbar_media_finder clearfix">
    <div class="media_categories_select">
        <?php echo CHtml::beginForm(); ?>
        Category:
        <?php

        $has_cache = Yii::app()->cache->get('cache_media_finder');
        if ($has_cache === false) {
            
            require_once(Yii::app()->basePath . '/extensions/GraphTree/tree.php');
            $datas = dumpArrayTree($datas);
            $media_categories = array(
                '0' => 'ΞΞ All Media Files ΞΞ',
                '1' => 'ΞΞ NODE ROOT ΞΞ'
            );
            if (count($datas)) {
                foreach ($datas as $data) {
                    $media_categories[$data['id']] = $data['levelstr'] . '⇒ ' . strip_tags($data['text']) . '《' . (string)$data['files_count'] . '》';
                }
            }
            Yii::app()->cache->set('cache_media_finder', $media_categories, 100);
        } else {
            $media_categories = Yii::app()->cache->get('cache_media_finder');
        }

        echo CHtml::dropDownList('category_id', 0, $media_categories,
        array('size' => 1, 'class' => 'dropdown', 'ajax' => array(
                'type' => 'GET',
                'url' => array('showCategoryMediaList'),
                'update' => '#media_lists',
                'beforeSend' => 'function() { $("#media_lists").addClass("datasLoading"); }',
                'complete' => 'function() { $("#media_lists").removeClass("datasLoading"); }',
            ),
            'prompt' => 'Please Select Category'
        ));
        ?>
        <?php
        echo CHtml::hiddenField('show_type', $show_type);
        echo CHtml::endForm();
        ?>
    </div>
    <div class="media_search" id="search">
        <?php echo CHtml::beginForm(array('media/search'), 'GET'); ?>
        
        <?php
//        echo CHtml::label('Search：', 'search');
        $this->widget('CAutoComplete',
            array(
                'name' => 'q',
                'value' => $sw,
                'max' => 200,
                'delay' => 300,
                'matchCase' => false,
                'url' => array('autocomplete'),
                'minChars' => 2,
                'inputClass' => 'sw',
                'scrollHeight' => 400,
                'resultsClass' => 'ac_results_fix',
            )
        );
        echo CHtml::ajaxButton('aJax Search', array('media/search'), array(
                'type' => 'GET',
                'url' => array('media/search'),
                'update' => '#media_lists',
                'beforeSend' => 'function() {
                    if ($.trim($("#q").val()) == "") {
                        alert("请输入您要查询的文件名。");
                        $("#q").focus();
                        return false;
                    }
                    $("#media_lists").addClass("datasLoading");
                 }',
                'complete' => 'function() { $("#media_lists").removeClass("datasLoading"); }',
            ),
            array('class' => 'btn'));
        echo CHtml::hiddenField('r', 'backend/media/search');
        echo CHtml::endForm();
        ?>
    </div>
</div>

<style type="text/css">
    div.datasLoading {
	width: 100%;
        text-align: center;
	height: 150px;
        float: right;
	text-indent: -9999em;
        background-position: center center;
        background-repeat: no-repeat;
        opacity: 1;
        background-image: url(<?php echo Yii::app()->baseUrl; ?>/assets/backend/images/ajaxLoader.gif);
    }
    div.datasLoading * {
        opacity: .2em;
    }
</style>